home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: HELP: UNIX's directory functions.
- Date: Sat, 24 Feb 96 14:32:30 GMT
- Organization: none
- Message-ID: <825172350snz@genesis.demon.co.uk>
- References: <Pine.ULT.3.91.960217002153.21669B-100000@hertz.njit.edu> <824598921snz@genesis.demon.co.uk> <4gigogINN8nq@keats.ugrad.cs.ubc.ca> <4gj6ug$o0h@news-f.iadfw.net>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4gj6ug$o0h@news-f.iadfw.net>
- alpet@airmail.net "Adam Peterson" writes:
-
- >c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) wrote:
- >
- >>In article <824598921snz@genesis.demon.co.uk>,
- >>Lawrence Kirby <fred@genesis.demon.co.uk> wrote:
- >> >In article <Pine.ULT.3.91.960217002153.21669B-100000@hertz.njit.edu>
- >> > dxp8108@hertz.njit.edu "Dharmesh Patel" writes:
- >> >
- >> >>
- >> >>Hi all!
- >> >>
- >> >>I need help with couple of things in C. I need to know how the functions
- >> >>opendir, readdir, closedir, and rewinddir work. I also need to know the
- >> >>elements of the struct dirent.
- >> >
- >> >Unfortunately these are not defined in C.
- >> >
- >> >>The reason for this request is that I have to write a program that
- >> >>simulates the unix command 'pwd', the hard way.
- >> >
- >> >They are Unix/POSIX defined functions and the place to ask about them
- >> >is comp.unix.programmer.
- >
- >>...and I might add that the revered "K&R" book does cover the basic UNIX
- >>programming interface, including directory functions, stat() and other
- > goodies.
- >
- >>It sounds like you don't have this book. Shame! :)
-
- My copy of K&R2 has a chapter on "The UNIX System Interface". The first
- paragraph makes the purpose of this chapter clear and the fact that it does
- not describe standard C functions. Schildt mingles DOS specific calls with
- standard C calls in his books. That does not mean that DOS specific calls
- are part of C. While K&R2 is a more reliable reference it no more defines
- ANSI C than do Schildt's books (at least the bits of them that Schildt
- wrote).
-
- >To answer the original question, Unix treats directories like files,
- >thus the open, read, close, rewind functions. To process a list of
- >files do something like this:
- >
- >if opendir succeeds
- >{
- > while not eof dir
- > readdir
- > closedir
- >}
-
- I don't see you using "the open, read, close, rewind functions" there! :-)
- (The point is that opendir etc. almost certainly use open etc. but present
- the data in a portable format).
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-